package edu.unc.comp410.colemangeer.demos;

import java.util.Set;

import org.apache.log4j.Logger;
import org.omg.CORBA.portable.ApplicationException;

import edu.unc.comp410.colemangeer.data.IProductGateway;
import edu.unc.comp410.colemangeer.data.ProductGateway;
import edu.unc.comp410.colemangeer.model.DataProvider;
import edu.unc.comp410.colemangeer.model.Product;

/**
 * 
 * Something like this is going to serve as the application container - 
 * it will know how to build the catalog, talk to the data gateways, setup the controller
 * classes, start the UI in a legal state, etc.
 * 
 * Or we make a System class that demos have a reference to 
 *  
 * @author ccoleman
 *
 */
public class ProductsDemo {
	
	private static Logger log = Logger.getLogger(ProductsDemo.class);
	private DataProvider dataProvider;
	private IProductGateway productsData;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ProductsDemo demo = new ProductsDemo();
		demo.dataProvider = new DataProvider();
		
		try {
			demo.productsData = demo.dataProvider.getProductGateway();
		} catch (ApplicationException e) {
			log.error("data provider could not get IProductGateway");
			e.printStackTrace();
		}
		
	 log.info(demo.productsData==null? "no gateway":"gateway!");
	 
	 if (demo.productsData!=null){
		 if (demo.productsData instanceof ProductGateway){
			 log.info("real gateway!");
		 }
	 }

	 Product productOne = demo.productsData.getByID(18);
	 
	 log.info("Product id " + productOne.getId() + " is " + productOne.getName());
	 System.out.println(productOne.toString());
	 
	 Set<Product> allProducts = demo.productsData.getAllProducts();

	 log.info("All Products:");
	 
	 for (Product p: allProducts){
		 log.info(p.toString());
	 }
	 
	}

}
